//
//  VisitorLoginView.swift
//  微博
//
//  Created by Mr.Deng on 15/9/23.
//  Copyright © 2015年 Mr.Deng. All rights reserved.
//

import UIKit
import SnapKit
//protocol visitorLoginViewDelegate : NSObjectProtocol{
//        func visitorViewDidRegister();
//        func vistiorViewDidLogin();
//    }
class VisitorLoginView: UIView {

        
    //从Storyboard中加载调用该方法
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setupUI()
    }
    
    //纯代码开发调用该方法
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    //改变不同控制器显示的图片与文字
    func setupUIInfo(imageName:String?, message:String?){
       messageLabel.text = message
        if let imageName = imageName{
            iconView.image = UIImage(named: imageName)
            homeIconView.hidden = true
            sendSubviewToBack(maskIconView)
        }else{
            startAnim()
        }
    }
    //增加动画
    private func startAnim(){
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        anim.repeatCount = MAXFLOAT
        anim.toValue = 2 * M_PI
        anim.duration = 20
        anim.removedOnCompletion = false
        iconView.layer.addAnimation(anim, forKey: nil)
}
    
    
    private func setupUI(){
        //取消子控件autoresizing
        backgroundColor = UIColor(white: 237.0 / 255.0, alpha: 1.0)
        for v in subviews{
            v.translatesAutoresizingMaskIntoConstraints = false
        }
        addSubview(iconView)
        addSubview(homeIconView)
        addSubview(messageLabel)
        addSubview(maskIconView)
        addSubview(registerBtn)
        addSubview(loginBtn)
        
        //添加约束
        iconView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.snp_centerX)
            make.centerY.equalTo(self.snp_centerY).offset(-60)
        }
        
        homeIconView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(iconView.snp_center)
        }
        
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconView.snp_centerX)
            make.top.equalTo(iconView.snp_bottom).offset(16)
            make.width.equalTo(224)
            make.height.equalTo(36)
        }
        
        maskIconView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left)
            make.right.equalTo(self.snp_right)
            make.bottom.equalTo(registerBtn.snp_bottom).offset(36)
        }
        registerBtn.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(messageLabel.snp_left)
            make.top.equalTo(messageLabel.snp_bottom).offset(16)
            make.width.equalTo(100)
            make.height.equalTo(36)
        }
        loginBtn.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(messageLabel.snp_right)
            make.top.equalTo(messageLabel.snp_bottom).offset(16)
            make.width.equalTo(100)
            make.height.equalTo(36)
        }
        
//        //添加按钮监听方法
//        registerBtn.addTarget(self, action: "register", forControlEvents: .TouchUpInside)
//        loginBtn.addTarget(self, action: "login", forControlEvents:  .TouchUpInside)
    }
    
    private lazy var iconView : UIImageView = UIImageView(imageName: "visitordiscover_feed_image_smallicon")
    
    private lazy var homeIconView : UIImageView = UIImageView(imageName: "visitordiscover_feed_image_house")
    //创建遮罩图层
    private lazy var maskIconView:UIImageView = UIImageView(imageName: "visitordiscover_feed_mask_smallicon")
    private lazy var messageLabel:UILabel = UILabel(title: "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜", fontSize: 14, color: UIColor.darkGrayColor())
     lazy var registerBtn:UIButton = UIButton(title: "注册", color: UIColor.orangeColor(), fontSize: 14, backgroundImageName: "common_button_white_disable")
     lazy var loginBtn:UIButton = UIButton(title: "登录", color: UIColor.darkGrayColor(), fontSize: 14, backgroundImageName: "common_button_white_disable")
}
